package com.hadoop.demo.mapreduce.flowcount;


import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * =================================
 * <p>
 * Created by cjj on 18-10-8.
 * <p>
 * 描述:
 */

public class FlowSumReduce extends Reducer<Text, FlowBean, Text, FlowBean> {

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        //super.reduce(key, values, context);

        long up_flow_count = 0;
        long down_flow_count = 0;

        for (FlowBean flowBean : values) {
            up_flow_count += flowBean.getUp_flow();
            down_flow_count += flowBean.getDown_flow();
        }
        context.write(key,new FlowBean(key.toString(),up_flow_count,down_flow_count));
    }
}
